package com.example.idachuappone.cook.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.example.idachuappone.index.entity.Comment;
import com.example.idachuappone.index.welcomentity.Packages;
import com.example.idachuappone.utils.ComUtil;

public class CookResult implements Serializable {
	private String bespeak_num;
	private String birth_year;
	private int city_id;
	private Comment comment;
	private int comment_num;
	private String description;
	private int digg_num;
	private int favorite_num;
	private String head;
	private String head_small;
	private String hometown;
	private String id;
	private int is_digg;
	private int is_favorite;
	private String location;
	private String name;
	private List<Packages> packages;
	private String phone;
	private List<Recipe> recipe;
	private String service_for;
	private String sex;
	private String star;
	private int status;
	private List<Tags> tags;
	private List<WorkDayTime> weekday;
	private List<WorkDay> work_day;
	private String work_year;

	public CookResult parseJson(JSONObject json) {
		if (json == null) {
			return null;
		}
		JSONArray jsonArray;
		int i;
		if (json.has("id")) {
			this.id = json.optString("id");
		}
		if (json.has("name")) {
			this.name = json.optString("name");
		}
		if (json.has("sex")) {
			this.sex = json.optString("sex");
		}
		if (json.has("birth_year")) {
			this.birth_year = json.optString("birth_year");
		}
		if (json.has("work_year")) {
			this.work_year = json.optString("work_year");
		}
		if (json.has("hometown")) {
			this.hometown = json.optString("hometown");
		}
		if (json.has("phone")) {
			this.phone = json.optString("phone");
		}
		if (json.has("head")) {
			this.head = json.optString("head");
		}
		if (json.has("head_small")) {
			this.head_small = json.optString("head_small");
		}
		if (json.has("service_for")) {
			this.service_for = json.optString("service_for");
		}
		if (json.has("location")) {
			this.location = json.optString("location");
		}
		if (json.has("description")) {
			this.description = json.optString("description");
		}

		if (json.has("status")) {
			this.status = json.optInt("status");
		}
		if (json.has("star")) {
			this.star = json.optString("star");
		}
		if (json.has("work_day")) {
			if (json.optJSONObject("work_day") != null) {
				Iterator<String> iterator = json.optJSONObject("work_day").keys();
				this.work_day = new ArrayList();
				while (iterator.hasNext()) {
					String key = iterator.next();
					try {
						String ss = json.optJSONObject("work_day").getString(key);
						WorkDay workDay = new WorkDay(key);
						workDay.parseJson(ss.substring(1, ss.length() - 1));
						this.work_day.add(workDay);
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
				for (int x = 0; x < this.work_day.size() - 1; x++) {
					for (int y = 0; y < (this.work_day.size() - x) - 1; y++) {
						if (ComUtil.getDateLong1(this.work_day.get(y).getDate()) > ComUtil.getDateLong1(this.work_day
								.get(y + 1).getDate())) {
							WorkDay item = this.work_day.get(y);
							this.work_day.set(y, this.work_day.get(y + 1));
							this.work_day.set(y + 1, item);
						}
					}
				}
			}
		}
		if (json.has("recipes")) {
			jsonArray = json.optJSONArray("recipes");
			this.recipe = new ArrayList();
			for (i = 0; i < jsonArray.length(); i++) {
				try {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					this.recipe.add(new Recipe().parseJson(jsonObject));
				} catch (JSONException e2) {
					e2.printStackTrace();
				}
			}
		}
		if (json.has("packages")) {
			jsonArray = json.optJSONArray("packages");
			this.packages = new ArrayList();
			for (i = 0; i < jsonArray.length(); i++) {
				try {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					this.packages.add(new Packages().parseJson(jsonObject));
				} catch (JSONException e22) {
					e22.printStackTrace();
				}
			}
		}
		if (json.has("tags")) {
			jsonArray = json.optJSONArray("tags");
			this.tags = new ArrayList();
			if (jsonArray != null && jsonArray.length() > 0) {
				for (i = 0; i < jsonArray.length(); i++) {
					try {
						JSONObject jsonObject = jsonArray.getJSONObject(i);

						this.tags.add(new Tags().parseJson(jsonObject));
					} catch (JSONException e222) {
						e222.printStackTrace();
					}
				}
			}
		}
		if (json.has("bespeak_num")) {
			this.bespeak_num = json.optString("bespeak_num");
		}
		if (json.has("comment")) {
			this.comment = new Comment().parseJson(json.optJSONObject("comment"));
		}
		if (json.has("favorite_num")) {
			this.favorite_num = json.optInt("favorite_num");
		}
		if (json.has("digg_num")) {
			this.digg_num = json.optInt("digg_num");
		}
		if (json.has("comment_num")) {
			this.comment_num = json.optInt("comment_num");
		}
		if (json.has("is_favorite")) {
			this.is_favorite = json.optInt("is_favorite");
		}
		if (json.has("is_digg")) {
			this.is_digg = json.optInt("is_digg");
		}
		if (json.has("weekday")) {
			jsonArray = json.optJSONArray("weekday");
			this.weekday = new ArrayList();
			if (jsonArray != null && jsonArray.length() > 0) {
				for (i = 0; i < jsonArray.length(); i++) {
					try {
						JSONObject jsonObject = jsonArray.getJSONObject(i);
						this.weekday.add(new WorkDayTime().parseJson(jsonObject));
					} catch (JSONException e2222) {
						e2222.printStackTrace();
					}
				}
			}
		}
		if (!json.has("city_id")) {
			return this;
		}
		this.city_id = json.optInt("city_id");
		return this;
	}

	public String getBespeak_num() {
		return this.bespeak_num;
	}

	public String getWork_year() {
		return this.work_year;
	}

	public void setWork_year(String work_year) {
		this.work_year = work_year;
	}

	public void setBespeak_num(String bespeak_num) {
		this.bespeak_num = bespeak_num;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSex() {
		return this.sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getBirth_year() {
		return this.birth_year;
	}

	public void setBirth_year(String birth_year) {
		this.birth_year = birth_year;
	}

	public String getHometown() {
		return this.hometown;
	}

	public void setHometown(String hometown) {
		this.hometown = hometown;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getHead() {
		return this.head;
	}

	public void setHead(String head) {
		this.head = head;
	}

	public String getHead_small() {
		return this.head_small;
	}

	public void setHead_small(String head_small) {
		this.head_small = head_small;
	}

	public String getService_for() {
		return this.service_for;
	}

	public void setService_for(String service_for) {
		this.service_for = service_for;
	}

	public String getLocation() {
		return this.location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStar() {
		return this.star;
	}

	public void setStar(String star) {
		this.star = star;
	}

	public List<WorkDay> getWork_day() {
		return this.work_day;
	}

	public void setWork_day(List<WorkDay> work_day) {
		this.work_day = work_day;
	}

	public List<Recipe> getRecipe() {
		return this.recipe;
	}

	public void setRecipe(List<Recipe> recipe) {
		this.recipe = recipe;
	}

	public List<Packages> getPackages() {
		return this.packages;
	}

	public void setPackages(List<Packages> packages) {
		this.packages = packages;
	}

	public List<Tags> getTags() {
		return this.tags;
	}

	public void setTags(List<Tags> tags) {
		this.tags = tags;
	}

	public int getFavorite_num() {
		return this.favorite_num;
	}

	public void setFavorite_num(int favorite_num) {
		this.favorite_num = favorite_num;
	}

	public int getDigg_num() {
		return this.digg_num;
	}

	public void setDigg_num(int digg_num) {
		this.digg_num = digg_num;
	}

	public int getIs_favorite() {
		return this.is_favorite;
	}

	public void setIs_favorite(int is_favorite) {
		this.is_favorite = is_favorite;
	}

	public int getIs_digg() {
		return this.is_digg;
	}

	public void setIs_digg(int is_digg) {
		this.is_digg = is_digg;
	}

	public Comment getComment() {
		return this.comment;
	}

	public void setComment(Comment comment) {
		this.comment = comment;
	}

	public List<WorkDayTime> getWorkday() {
		return this.weekday;
	}

	public void setWorkday(List<WorkDayTime> workday) {
		this.weekday = workday;
	}

	public int getComment_num() {
		return this.comment_num;
	}

	public void setComment_num(int comment_num) {
		this.comment_num = comment_num;
	}

	public int getCity_id() {
		return this.city_id;
	}

	public void setCity_id(int city_id) {
		this.city_id = city_id;
	}

	public int getStatus() {
		return this.status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
}
